{
  "cells": [
    {
      "cell_type": "markdown",
      "source": [
        "# Convolutional Neural Networks (CNN)"
      ],
      "metadata": {
        "nteract": {
          "transient": {
            "deleting": false
          }
        }
      }
    },
    {
      "cell_type": "code",
      "source": [
        "import numpy as np\n",
        "import matplotlib.pyplot as plt\n",
        "import pandas as pd\n",
        "\n",
        "import warnings\n",
        "warnings.filterwarnings(\"ignore\")\n",
        "\n",
        "import yfinance as yf\n",
        "yf.pdr_override()"
      ],
      "outputs": [],
      "execution_count": 1,
      "metadata": {
        "collapsed": true,
        "jupyter": {
          "source_hidden": false,
          "outputs_hidden": false
        },
        "nteract": {
          "transient": {
            "deleting": false
          }
        },
        "execution": {
          "iopub.status.busy": "2022-07-21T18:18:32.530Z",
          "iopub.execute_input": "2022-07-21T18:18:32.534Z",
          "shell.execute_reply": "2022-07-21T18:18:32.760Z",
          "iopub.status.idle": "2022-07-21T18:18:32.767Z"
        }
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# input\n",
        "symbol = 'AMD'\n",
        "start = '2014-01-01'\n",
        "end = '2018-08-27'\n",
        "\n",
        "# Read data \n",
        "dataset = yf.download(symbol,start,end)\n",
        "\n",
        "# View Columns\n",
        "dataset.head()"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "[*********************100%***********************]  1 of 1 completed\n"
          ]
        },
        {
          "output_type": "execute_result",
          "execution_count": 2,
          "data": {
            "text/plain": "            Open  High   Low  Close  Adj Close    Volume\nDate                                                    \n2014-01-02  3.85  3.98  3.84   3.95       3.95  20548400\n2014-01-03  3.98  4.00  3.88   4.00       4.00  22887200\n2014-01-06  4.01  4.18  3.99   4.13       4.13  42398300\n2014-01-07  4.19  4.25  4.11   4.18       4.18  42932100\n2014-01-08  4.23  4.26  4.14   4.18       4.18  30678700",
            "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>Open</th>\n      <th>High</th>\n      <th>Low</th>\n      <th>Close</th>\n      <th>Adj Close</th>\n      <th>Volume</th>\n    </tr>\n    <tr>\n      <th>Date</th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>2014-01-02</th>\n      <td>3.85</td>\n      <td>3.98</td>\n      <td>3.84</td>\n      <td>3.95</td>\n      <td>3.95</td>\n      <td>20548400</td>\n    </tr>\n    <tr>\n      <th>2014-01-03</th>\n      <td>3.98</td>\n      <td>4.00</td>\n      <td>3.88</td>\n      <td>4.00</td>\n      <td>4.00</td>\n      <td>22887200</td>\n    </tr>\n    <tr>\n      <th>2014-01-06</th>\n      <td>4.01</td>\n      <td>4.18</td>\n      <td>3.99</td>\n      <td>4.13</td>\n      <td>4.13</td>\n      <td>42398300</td>\n    </tr>\n    <tr>\n      <th>2014-01-07</th>\n      <td>4.19</td>\n      <td>4.25</td>\n      <td>4.11</td>\n      <td>4.18</td>\n      <td>4.18</td>\n      <td>42932100</td>\n    </tr>\n    <tr>\n      <th>2014-01-08</th>\n      <td>4.23</td>\n      <td>4.26</td>\n      <td>4.14</td>\n      <td>4.18</td>\n      <td>4.18</td>\n      <td>30678700</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
          },
          "metadata": {}
        }
      ],
      "execution_count": 2,
      "metadata": {
        "collapsed": true,
        "jupyter": {
          "source_hidden": false,
          "outputs_hidden": false
        },
        "nteract": {
          "transient": {
            "deleting": false
          }
        },
        "execution": {
          "iopub.status.busy": "2022-07-21T18:18:32.773Z",
          "iopub.execute_input": "2022-07-21T18:18:32.778Z",
          "iopub.status.idle": "2022-07-21T18:18:33.437Z",
          "shell.execute_reply": "2022-07-21T18:18:33.431Z"
        }
      }
    },
    {
      "cell_type": "code",
      "source": [
        "dataset['Increase_Decrease'] = np.where(dataset['Volume'].shift(-1) > dataset['Volume'],1,0)\n",
        "dataset['Buy_Sell_on_Open'] = np.where(dataset['Open'].shift(-1) > dataset['Open'],1,0)\n",
        "dataset['Buy_Sell'] = np.where(dataset['Adj Close'].shift(-1) > dataset['Adj Close'],1,0)\n",
        "dataset['Returns'] = dataset['Adj Close'].pct_change()\n",
        "dataset = dataset.dropna()"
      ],
      "outputs": [],
      "execution_count": 3,
      "metadata": {
        "collapsed": true,
        "jupyter": {
          "source_hidden": false,
          "outputs_hidden": false
        },
        "nteract": {
          "transient": {
            "deleting": false
          }
        },
        "execution": {
          "iopub.status.busy": "2022-07-21T18:18:33.443Z",
          "iopub.execute_input": "2022-07-21T18:18:33.448Z",
          "iopub.status.idle": "2022-07-21T18:18:33.455Z",
          "shell.execute_reply": "2022-07-21T18:18:33.543Z"
        }
      }
    },
    {
      "cell_type": "code",
      "source": [
        "dataset.head()"
      ],
      "outputs": [
        {
          "output_type": "execute_result",
          "execution_count": 4,
          "data": {
            "text/plain": "            Open  High   Low  Close  Adj Close    Volume  Increase_Decrease  \\\nDate                                                                          \n2014-01-03  3.98  4.00  3.88   4.00       4.00  22887200                  1   \n2014-01-06  4.01  4.18  3.99   4.13       4.13  42398300                  1   \n2014-01-07  4.19  4.25  4.11   4.18       4.18  42932100                  0   \n2014-01-08  4.23  4.26  4.14   4.18       4.18  30678700                  0   \n2014-01-09  4.20  4.23  4.05   4.09       4.09  30667600                  0   \n\n            Buy_Sell_on_Open  Buy_Sell   Returns  \nDate                                              \n2014-01-03                 1         1  0.012658  \n2014-01-06                 1         1  0.032500  \n2014-01-07                 1         0  0.012106  \n2014-01-08                 0         0  0.000000  \n2014-01-09                 0         1 -0.021531  ",
            "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>Open</th>\n      <th>High</th>\n      <th>Low</th>\n      <th>Close</th>\n      <th>Adj Close</th>\n      <th>Volume</th>\n      <th>Increase_Decrease</th>\n      <th>Buy_Sell_on_Open</th>\n      <th>Buy_Sell</th>\n      <th>Returns</th>\n    </tr>\n    <tr>\n      <th>Date</th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>2014-01-03</th>\n      <td>3.98</td>\n      <td>4.00</td>\n      <td>3.88</td>\n      <td>4.00</td>\n      <td>4.00</td>\n      <td>22887200</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>0.012658</td>\n    </tr>\n    <tr>\n      <th>2014-01-06</th>\n      <td>4.01</td>\n      <td>4.18</td>\n      <td>3.99</td>\n      <td>4.13</td>\n      <td>4.13</td>\n      <td>42398300</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>0.032500</td>\n    </tr>\n    <tr>\n      <th>2014-01-07</th>\n      <td>4.19</td>\n      <td>4.25</td>\n      <td>4.11</td>\n      <td>4.18</td>\n      <td>4.18</td>\n      <td>42932100</td>\n      <td>0</td>\n      <td>1</td>\n      <td>0</td>\n      <td>0.012106</td>\n    </tr>\n    <tr>\n      <th>2014-01-08</th>\n      <td>4.23</td>\n      <td>4.26</td>\n      <td>4.14</td>\n      <td>4.18</td>\n      <td>4.18</td>\n      <td>30678700</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0.000000</td>\n    </tr>\n    <tr>\n      <th>2014-01-09</th>\n      <td>4.20</td>\n      <td>4.23</td>\n      <td>4.05</td>\n      <td>4.09</td>\n      <td>4.09</td>\n      <td>30667600</td>\n      <td>0</td>\n      <td>0</td>\n      <td>1</td>\n      <td>-0.021531</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
          },
          "metadata": {}
        }
      ],
      "execution_count": 4,
      "metadata": {
        "collapsed": true,
        "jupyter": {
          "source_hidden": false,
          "outputs_hidden": false
        },
        "nteract": {
          "transient": {
            "deleting": false
          }
        },
        "execution": {
          "iopub.status.busy": "2022-07-21T18:18:33.461Z",
          "iopub.execute_input": "2022-07-21T18:18:33.465Z",
          "iopub.status.idle": "2022-07-21T18:18:33.475Z",
          "shell.execute_reply": "2022-07-21T18:18:33.546Z"
        }
      }
    },
    {
      "cell_type": "code",
      "source": [
        "dataset.tail()"
      ],
      "outputs": [
        {
          "output_type": "execute_result",
          "execution_count": 5,
          "data": {
            "text/plain": "                 Open   High        Low      Close  Adj Close     Volume  \\\nDate                                                                       \n2018-08-20  19.790001  20.08  19.350000  19.980000  19.980000   62983200   \n2018-08-21  19.980000  20.42  19.860001  20.400000  20.400000   55629000   \n2018-08-22  20.280001  20.92  20.209999  20.900000  20.900000   62002700   \n2018-08-23  21.190001  22.32  21.139999  22.290001  22.290001  113444100   \n2018-08-24  22.910000  24.00  22.670000  23.980000  23.980000  164328200   \n\n            Increase_Decrease  Buy_Sell_on_Open  Buy_Sell   Returns  \nDate                                                                 \n2018-08-20                  0                 1         1  0.010622  \n2018-08-21                  1                 1         1  0.021021  \n2018-08-22                  1                 1         1  0.024510  \n2018-08-23                  1                 1         1  0.066507  \n2018-08-24                  0                 0         0  0.075819  ",
            "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>Open</th>\n      <th>High</th>\n      <th>Low</th>\n      <th>Close</th>\n      <th>Adj Close</th>\n      <th>Volume</th>\n      <th>Increase_Decrease</th>\n      <th>Buy_Sell_on_Open</th>\n      <th>Buy_Sell</th>\n      <th>Returns</th>\n    </tr>\n    <tr>\n      <th>Date</th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>2018-08-20</th>\n      <td>19.790001</td>\n      <td>20.08</td>\n      <td>19.350000</td>\n      <td>19.980000</td>\n      <td>19.980000</td>\n      <td>62983200</td>\n      <td>0</td>\n      <td>1</td>\n      <td>1</td>\n      <td>0.010622</td>\n    </tr>\n    <tr>\n      <th>2018-08-21</th>\n      <td>19.980000</td>\n      <td>20.42</td>\n      <td>19.860001</td>\n      <td>20.400000</td>\n      <td>20.400000</td>\n      <td>55629000</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>0.021021</td>\n    </tr>\n    <tr>\n      <th>2018-08-22</th>\n      <td>20.280001</td>\n      <td>20.92</td>\n      <td>20.209999</td>\n      <td>20.900000</td>\n      <td>20.900000</td>\n      <td>62002700</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>0.024510</td>\n    </tr>\n    <tr>\n      <th>2018-08-23</th>\n      <td>21.190001</td>\n      <td>22.32</td>\n      <td>21.139999</td>\n      <td>22.290001</td>\n      <td>22.290001</td>\n      <td>113444100</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>0.066507</td>\n    </tr>\n    <tr>\n      <th>2018-08-24</th>\n      <td>22.910000</td>\n      <td>24.00</td>\n      <td>22.670000</td>\n      <td>23.980000</td>\n      <td>23.980000</td>\n      <td>164328200</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0.075819</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
          },
          "metadata": {}
        }
      ],
      "execution_count": 5,
      "metadata": {
        "collapsed": true,
        "jupyter": {
          "source_hidden": false,
          "outputs_hidden": false
        },
        "nteract": {
          "transient": {
            "deleting": false
          }
        },
        "execution": {
          "iopub.status.busy": "2022-07-21T18:18:33.481Z",
          "iopub.execute_input": "2022-07-21T18:18:33.485Z",
          "iopub.status.idle": "2022-07-21T18:18:33.494Z",
          "shell.execute_reply": "2022-07-21T18:18:33.549Z"
        }
      }
    },
    {
      "cell_type": "code",
      "source": [
        "dataset.shape"
      ],
      "outputs": [
        {
          "output_type": "execute_result",
          "execution_count": 6,
          "data": {
            "text/plain": "(1170, 10)"
          },
          "metadata": {}
        }
      ],
      "execution_count": 6,
      "metadata": {
        "collapsed": true,
        "jupyter": {
          "source_hidden": false,
          "outputs_hidden": false
        },
        "nteract": {
          "transient": {
            "deleting": false
          }
        },
        "execution": {
          "iopub.status.busy": "2022-07-21T18:18:33.500Z",
          "iopub.execute_input": "2022-07-21T18:18:33.504Z",
          "iopub.status.idle": "2022-07-21T18:18:33.513Z",
          "shell.execute_reply": "2022-07-21T18:18:33.552Z"
        }
      }
    },
    {
      "cell_type": "code",
      "source": [
        "from keras.models import Sequential\n",
        "from keras.layers import Dense\n",
        "from keras.layers import Flatten\n",
        "from keras.layers.convolutional import Conv1D\n",
        "from keras.layers.convolutional import MaxPooling1D"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stderr",
          "text": [
            "Using TensorFlow backend.\n"
          ]
        }
      ],
      "execution_count": 7,
      "metadata": {
        "collapsed": true,
        "jupyter": {
          "source_hidden": false,
          "outputs_hidden": false
        },
        "nteract": {
          "transient": {
            "deleting": false
          }
        },
        "execution": {
          "iopub.status.busy": "2022-07-21T18:18:33.521Z",
          "iopub.execute_input": "2022-07-21T18:18:33.525Z",
          "shell.execute_reply": "2022-07-21T18:18:34.542Z",
          "iopub.status.idle": "2022-07-21T18:18:34.473Z"
        }
      }
    },
    {
      "cell_type": "code",
      "source": [
        "def split_sequence(sequence, steps):\n",
        "  X, y = list(), list()\n",
        "  for start in range(len(sequence)):\n",
        "    # define the end index of the sequence\n",
        "    end_index = start + steps\n",
        "    # to check if end_index stays in the allowable limit\n",
        "    if end_index > len(sequence)-1:\n",
        "      break\n",
        "    # extract input and output parts of the sequence\n",
        "    sequence_x, sequence_y = sequence[start : end_index], sequence[end_index]\n",
        "    X.append(sequence_x)\n",
        "    y.append(sequence_y)\n",
        "  return np.array(X), np.array(y)"
      ],
      "outputs": [],
      "execution_count": 8,
      "metadata": {
        "collapsed": true,
        "jupyter": {
          "source_hidden": false,
          "outputs_hidden": false
        },
        "nteract": {
          "transient": {
            "deleting": false
          }
        },
        "execution": {
          "iopub.status.busy": "2022-07-21T18:18:34.479Z",
          "iopub.execute_input": "2022-07-21T18:18:34.482Z",
          "iopub.status.idle": "2022-07-21T18:18:34.488Z",
          "shell.execute_reply": "2022-07-21T18:18:34.545Z"
        }
      }
    },
    {
      "cell_type": "code",
      "source": [
        "raw_sequence = np.array(dataset['Adj Close'])\n",
        "\n",
        "# choose a number of time steps\n",
        "steps = 3\n",
        "\n",
        "# split into samples\n",
        "X, y = split_sequence(raw_sequence, steps)\n",
        "\n",
        "print(\"**************************************************************\")\n",
        "print(\"The input raw sequence on which we will test our CNN model\")\n",
        "print(raw_sequence)\n",
        "print(\"**************************************************************\")\n",
        "print(\"The features (X) ,lagged values of time series, for our CNN model\")\n",
        "print(X)\n",
        "print(\"**************************************************************\")\n",
        "print(\"The respective observed values (y) of the sequence for training in CNN model\")\n",
        "print(y)\n",
        "print(\"**************************************************************\")"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "**************************************************************\n",
            "The input raw sequence on which we will test our CNN model\n",
            "[ 4.          4.13000011  4.17999983 ... 20.89999962 22.29000092\n",
            " 23.97999954]\n",
            "**************************************************************\n",
            "The features (X) ,lagged values of time series, for our CNN model\n",
            "[[ 4.          4.13000011  4.17999983]\n",
            " [ 4.13000011  4.17999983  4.17999983]\n",
            " [ 4.17999983  4.17999983  4.09000015]\n",
            " ...\n",
            " [19.77000046 19.97999954 20.39999962]\n",
            " [19.97999954 20.39999962 20.89999962]\n",
            " [20.39999962 20.89999962 22.29000092]]\n",
            "**************************************************************\n",
            "The respective observed values (y) of the sequence for training in CNN model\n",
            "[ 4.17999983  4.09000015  4.17000008 ... 20.89999962 22.29000092\n",
            " 23.97999954]\n",
            "**************************************************************\n"
          ]
        }
      ],
      "execution_count": 9,
      "metadata": {
        "collapsed": true,
        "jupyter": {
          "source_hidden": false,
          "outputs_hidden": false
        },
        "nteract": {
          "transient": {
            "deleting": false
          }
        },
        "execution": {
          "iopub.status.busy": "2022-07-21T18:18:34.495Z",
          "iopub.execute_input": "2022-07-21T18:18:34.499Z",
          "iopub.status.idle": "2022-07-21T18:18:34.508Z",
          "shell.execute_reply": "2022-07-21T18:18:34.548Z"
        }
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# reshape 2D input data to 3D input data\n",
        "features = 1\n",
        "X = X.reshape((X.shape[0], X.shape[1], features))\n",
        "\n",
        "print(\"After reshaping , the shape of input X\")\n",
        "print(X.shape)\n",
        "print(\"**************************************************************\")\n",
        "print(\"**************************************************************\")\n",
        "print(\"The final form of input feature matrix X\")\n",
        "print(X)\n",
        "print(\"**************************************************************\")\n",
        "print(\"**************************************************************\")\n",
        "print(\"Feature matrix X is ready for input to CNN model.We have used feature engineering\" \n",
        "    +\"to convert a sequence to matrix with image matrix shape to find patterns in sequence\")\n",
        "print(\"**************************************************************\")"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "After reshaping , the shape of input X\n",
            "(1167, 3, 1)\n",
            "**************************************************************\n",
            "**************************************************************\n",
            "The final form of input feature matrix X\n",
            "[[[ 4.        ]\n",
            "  [ 4.13000011]\n",
            "  [ 4.17999983]]\n",
            "\n",
            " [[ 4.13000011]\n",
            "  [ 4.17999983]\n",
            "  [ 4.17999983]]\n",
            "\n",
            " [[ 4.17999983]\n",
            "  [ 4.17999983]\n",
            "  [ 4.09000015]]\n",
            "\n",
            " ...\n",
            "\n",
            " [[19.77000046]\n",
            "  [19.97999954]\n",
            "  [20.39999962]]\n",
            "\n",
            " [[19.97999954]\n",
            "  [20.39999962]\n",
            "  [20.89999962]]\n",
            "\n",
            " [[20.39999962]\n",
            "  [20.89999962]\n",
            "  [22.29000092]]]\n",
            "**************************************************************\n",
            "**************************************************************\n",
            "Feature matrix X is ready for input to CNN model.We have used feature engineeringto convert a sequence to matrix with image matrix shape to find patterns in sequence\n",
            "**************************************************************\n"
          ]
        }
      ],
      "execution_count": 10,
      "metadata": {
        "collapsed": true,
        "jupyter": {
          "source_hidden": false,
          "outputs_hidden": false
        },
        "nteract": {
          "transient": {
            "deleting": false
          }
        },
        "execution": {
          "iopub.status.busy": "2022-07-21T18:18:34.514Z",
          "iopub.execute_input": "2022-07-21T18:18:34.517Z",
          "iopub.status.idle": "2022-07-21T18:18:34.527Z",
          "shell.execute_reply": "2022-07-21T18:18:34.550Z"
        }
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# Defining model Architecture\n",
        "model = Sequential()\n",
        "model.add(Conv1D(filters=64, kernel_size=2, activation='relu', input_shape=(steps,\n",
        "features)))\n",
        "model.add(MaxPooling1D(pool_size=2))\n",
        "model.add(Flatten())\n",
        "model.add(Dense(100, activation='relu'))\n",
        "model.add(Dense(1))\n",
        "model.compile(optimizer='adam', loss='mse')"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "WARNING:tensorflow:From C:\\Users\\Tin Hang\\Anaconda3\\lib\\site-packages\\tensorflow\\python\\ops\\resource_variable_ops.py:435: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version.\n",
            "Instructions for updating:\n",
            "Colocations handled automatically by placer.\n"
          ]
        }
      ],
      "execution_count": 11,
      "metadata": {
        "collapsed": true,
        "jupyter": {
          "source_hidden": false,
          "outputs_hidden": false
        },
        "nteract": {
          "transient": {
            "deleting": false
          }
        },
        "execution": {
          "iopub.status.busy": "2022-07-21T18:18:34.533Z",
          "iopub.execute_input": "2022-07-21T18:18:34.536Z",
          "iopub.status.idle": "2022-07-21T18:18:34.614Z",
          "shell.execute_reply": "2022-07-21T18:18:34.607Z"
        }
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# fit model\n",
        "model.fit(X, y, epochs=10000, verbose=0)"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "WARNING:tensorflow:From C:\\Users\\Tin Hang\\Anaconda3\\lib\\site-packages\\tensorflow\\python\\ops\\math_ops.py:3066: to_int32 (from tensorflow.python.ops.math_ops) is deprecated and will be removed in a future version.\n",
            "Instructions for updating:\n",
            "Use tf.cast instead.\n"
          ]
        },
        {
          "output_type": "execute_result",
          "execution_count": 12,
          "data": {
            "text/plain": "<keras.callbacks.callbacks.History at 0x17b550f5b70>"
          },
          "metadata": {}
        }
      ],
      "execution_count": 12,
      "metadata": {
        "collapsed": true,
        "jupyter": {
          "source_hidden": false,
          "outputs_hidden": false
        },
        "nteract": {
          "transient": {
            "deleting": false
          }
        },
        "execution": {
          "iopub.status.busy": "2022-07-21T18:18:34.620Z",
          "iopub.execute_input": "2022-07-21T18:18:34.624Z",
          "iopub.status.idle": "2022-07-21T18:21:43.507Z",
          "shell.execute_reply": "2022-07-21T18:21:43.535Z"
        }
      }
    },
    {
      "cell_type": "code",
      "source": [
        "#Testing the Model\n",
        "x_input = np.array([ 70, 80, 90 ])\n",
        "x_input = x_input.reshape((1, steps, features))\n",
        "y_pred = model.predict(x_input, verbose=0)\n",
        "print(\"**************************************************************\")\n",
        "print(f\"The next predicted value for the sequence {raw_sequence} is\")\n",
        "print(y_pred)\n",
        "print(\"**************************************************************\")\n",
        "\n"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "**************************************************************\n",
            "The next predicted value for the sequence [ 4.          4.13000011  4.17999983 ... 20.89999962 22.29000092\n",
            " 23.97999954] is\n",
            "[[108.246506]]\n",
            "**************************************************************\n"
          ]
        }
      ],
      "execution_count": 13,
      "metadata": {
        "collapsed": true,
        "jupyter": {
          "source_hidden": false,
          "outputs_hidden": false
        },
        "nteract": {
          "transient": {
            "deleting": false
          }
        },
        "execution": {
          "iopub.status.busy": "2022-07-21T18:21:43.517Z",
          "iopub.execute_input": "2022-07-21T18:21:43.522Z",
          "shell.execute_reply": "2022-07-21T18:21:43.539Z",
          "iopub.status.idle": "2022-07-21T18:21:43.546Z"
        }
      }
    }
  ],
  "metadata": {
    "kernel_info": {
      "name": "python3"
    },
    "language_info": {
      "name": "python",
      "version": "3.6.13",
      "mimetype": "text/x-python",
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "pygments_lexer": "ipython3",
      "nbconvert_exporter": "python",
      "file_extension": ".py"
    },
    "kernelspec": {
      "argv": [
        "C:/Users/Tin Hang/Anaconda3\\python.exe",
        "-m",
        "ipykernel_launcher",
        "-f",
        "{connection_file}"
      ],
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "nteract": {
      "version": "0.28.0"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}